package cn.iocoder.yudao.module.digital.dal.mysql.cardkeythirdpartyapirecord;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.digital.dal.dataobject.cardkeythirdpartyapirecord.CardkeyThirdPartyApiRecordDO;
import cn.iocoder.yudao.module.digital.service.cardchannel.model.ListByFailedHttpCodeVO;
import cn.iocoder.yudao.module.digital.service.cardchannel.model.ListByHttpStatusCodesVO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.digital.controller.admin.cardkeythirdpartyapirecord.vo.*;

/**
 * 卡密第三方API请求记录 Mapper
 *
 * @author 超管
 */
@Mapper
public interface CardkeyThirdPartyApiRecordMapper extends BaseMapperX<CardkeyThirdPartyApiRecordDO> {

    default PageResult<CardkeyThirdPartyApiRecordDO> selectPage(CardkeyThirdPartyApiRecordPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CardkeyThirdPartyApiRecordDO>()
                .eqIfPresent(CardkeyThirdPartyApiRecordDO::getProductNo, reqVO.getProductNo())
                .eqIfPresent(CardkeyThirdPartyApiRecordDO::getRequestType, reqVO.getRequestType())
                .eqIfPresent(CardkeyThirdPartyApiRecordDO::getRequestId, reqVO.getRequestId())
                .eqIfPresent(CardkeyThirdPartyApiRecordDO::getOrderNo, reqVO.getOrderNo())
                .eqIfPresent(CardkeyThirdPartyApiRecordDO::getUserId, reqVO.getUserId())
                .eqIfPresent(CardkeyThirdPartyApiRecordDO::getHttpStatusCode, reqVO.getHttpStatusCode())
                .betweenIfPresent(CardkeyThirdPartyApiRecordDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CardkeyThirdPartyApiRecordDO::getId));
    }

    default PageResult<CardkeyThirdPartyApiRecordDO> listByHttpStatusCodesNotRevert(ListByHttpStatusCodesVO vo) {
        return selectPage(vo, new LambdaQueryWrapperX<CardkeyThirdPartyApiRecordDO>()
                .eq(CardkeyThirdPartyApiRecordDO::getReverse, false)
                .eq(CardkeyThirdPartyApiRecordDO::getRequestType, vo.getRequestType().getValue())
                .in(CardkeyThirdPartyApiRecordDO::getHttpStatusCode, vo.getHttpStatusCodes())
                .ge(CardkeyThirdPartyApiRecordDO::getUpdateTime, new Date(System.currentTimeMillis() - 1000 * 60 * vo.getMinutesAgo()))
                .orderByAsc(CardkeyThirdPartyApiRecordDO::getUpdateTime));
    }

    default PageResult<CardkeyThirdPartyApiRecordDO> listByFailedHttpCodeNotRevert(ListByFailedHttpCodeVO vo) {
        return selectPage(vo, new LambdaQueryWrapperX<CardkeyThirdPartyApiRecordDO>()
                .eq(CardkeyThirdPartyApiRecordDO::getReverse, false)
                .eq(CardkeyThirdPartyApiRecordDO::getRequestType, vo.getRequestType().getValue())
                .ne(CardkeyThirdPartyApiRecordDO::getHttpStatusCode, 200)
                .ge(CardkeyThirdPartyApiRecordDO::getUpdateTime, new Date(System.currentTimeMillis() - 1000 * 60 * vo.getMinutesAgo()))
                .orderByAsc(CardkeyThirdPartyApiRecordDO::getUpdateTime));
    }

}